<?php
//$Id: object.php 9 2009-04-26 06:35:12Z bole.Chen $

class Object {

    var $get;
    var $post;
    var $request;

    var $cfg;

    var $debug;

/**
  * A hack to support __construct() on PHP 4
  * Hint: descendant classes have no PHP4 class_name() constructors,
  * so this one gets called first and calls the top-layer __construct()
  * which (if present) should call parent::__construct()
  *
  * @return Object
  */
    function Object() {
        global $CFG;

        $this->get      =& $_GET;
        $this->post     =& $_POST;
        $this->request  =& $_REQUEST;
        $this->cfg      =& $CFG;

        $this->debug = DEBUG;

        $args = func_get_args();
        if (PHP_VERSION < 5) {
            if (method_exists($this, '__destruct'))     register_shutdown_function(array(&$this, '__destruct'));
            if (method_exists($this, '__construct'))    call_user_func_array(array(&$this, '__construct'), $args);
        }
    }

/**
  * Object-to-string conversion
  * Each class can override it as necessary
  *
  * @return string this class' name
  */
    function toString () {
        return get_class($this);
    }

    function debugmsg($msg=null) {
        if ($this->debug) {
            if (is_array($msg)) $msg = print_r($msg, true);
            if (is_object($msg)) $msg = print_r($msg, true);
            if ($msg == null) $msg = $this->toString().'::';
            echo $msg.'<br />';
        }
    }

    function logger($msg, $logfile='default.log') {
        $logfile = ROOT.'logs'.DS.$logfile;
        $msg = date('Y-m-d H:i:s')." $msg\n";
        error_log($msg, 3, $logfile);
    }

}
?>
